define(["require", "exports", "./CommonFunction", "./EventDefinition", "./ListenerCenter", "./GlobalDefinition"], function (require, exports, CommonFunction_1, EventDefinition_1, ListenerCenter_1, GlobalDefinition_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**文件处理类 */
    class FileDisposClass {
        constructor() {
            this.CurrentData = [];
            this.Index = 0; //图片顺序标记索引
            this.CF = CommonFunction_1.CommonFunction.ins();
            this.startIndexEle = this.CF.IdToElement("setBlockStartIndex");
            this.Index = parseInt(this.startIndexEle.value);
        }
        /**绑定文件拖放的标签
         * @param ele: 要绑定的标签
         * @param ele_id: 绑定标签的名称
         * @param ele_drop: 文件显示的位置
         * @param file_type: 文件类型
        */
        BindLabelDrop(ele, ele_id, ele_drop) {
            let GCLC = new ListenerCenter_1.ListenerCenter();
            ele = this.CF.IdToElement(ele_id);
            GCLC.addEvent(EventDefinition_1.EventDefinition.DROP, ele, this.DropCallBack.bind(this), ele_drop);
            GCLC.addEvent(EventDefinition_1.EventDefinition.DROPOVER, ele, this.DragCallBack.bind(this), ele_drop);
        }
        /**拖放时的回调方法 */
        DropCallBack(e, event) {
            let files = [];
            let show_ele = e[1];
            this.startIndexEle.disabled = true; //设置为不可编辑
            //this.Index = this.CurrentData.length;
            this.Index = parseInt(this.startIndexEle.value);
            console.log(this.Index);
            event.preventDefault(); //取消事件默认动作
            if (event.type == "drop") {
                files = event.dataTransfer.files;
                for (let inx = 0; inx < files.length; inx++) {
                    //正则判断上传的文件是否为图片
                    if (/image/.test(files[inx].type)) {
                        let reader = new FileReader();
                        let file_data = new FileData();
                        let end = 0;
                        file_data.FileName = files[inx].name;
                        file_data.FileReader = reader;
                        file_data.ShowEle = show_ele;
                        reader.readAsDataURL(files[inx]);
                        this.CurrentData.push(file_data);
                        end = this.CurrentData.length - 1; //从尾部取出上传数据，方便后续上传的图块信息不至于混乱
                        reader.onload = this.ShowCallBack.bind(this, this.CurrentData[end]); //加载完成后回调
                    }
                }
            }
        }
        /**拖放结束的回调方法 */
        DragCallBack(e, event) {
            event.preventDefault();
        }
        /**显示回调处理 */
        ShowCallBack(file_data) {
            let id_str = "";
            let img = document.createElement("img"); //创建一个img元素
            let div = document.createElement("div");
            if (file_data != null) {
                this.Index += 1;
                id_str = file_data.FileName.replace(/.png|.jpg/, ""); //剔除图片名称后缀方便做id
                //img.id = id_str;
                div.id = id_str;
                div.style.textAlign = "center";
                div.style.verticalAlign = "midden";
                img.src = file_data.FileReader.result + "";
                img.title = file_data.FileName; //提示信息
                img.title += "@" + this.Index; //将图块序号存入title
                div.style.margin = "4px";
                div.style.width = GlobalDefinition_1.GlobalDefinition.BlockWidth + 8 + "px";
                div.style.height = GlobalDefinition_1.GlobalDefinition.BlockHeight + 8 + "px";
                img.style.margin = "4px 2px";
                div.appendChild(img);
                file_data.ShowEle.appendChild(div); //添加元素
            }
        }
    }
    exports.FileDisposClass = FileDisposClass;
    /**文件数据对象 */
    class FileData {
        constructor() {
            this.FileName = ""; //文件名称
        }
    }
});
